package unit9_10;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/*
* 增加插入：
* */

public class testDemo {
    static Connection conn=null;
    static Statement statement=null;

    public static void main(String[] args) {
        try {
            conn=JDBC_test2.getConn();//获取公共的连接对象

            Scanner input=new Scanner(System.in);
//            System.out.println("输入Id");
//            int id=input.nextInt();
            System.out.println("输入姓名");
            String name=input.next();
            System.out.println("输入年龄");
            int age=input.nextInt();
            System.out.println("输入性别");
            String sex=input.next();

//        编写sql语句
            String usql="insert into person (name,age,sex)"+"values('"+name+"',"+age+",'"+sex+"')";
//            用statement对象用来执行sql
            statement = conn.createStatement();
//            执行sql并获取查询语句
            statement.execute(usql);

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally{
            try {
                conn.close();
                statement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

        }
    }



}
